<template>
	<view class="content">
		<view class="app-title ac">
			<view class="fl" @click="back"><image class="back" src="/static/img/back.png"></image></view>问题列表
			<view class="fr" @click="addQuestion">新增<!-- <image class="more" src="/static/img/add-question.png"></image> --></view>
		</view>
		
		<view class="my-work ac">
			<view class="fl menu ac"><view :class="{on:tab == 4}" @click="setTab(4)"><b>全部</b></view><view v-show="tab == 4" class="num ac">{{count > 99 ? '99+' : count}}</view></view>
			<view class="fl menu ac"><view :class="{on:tab == 0}" @click="setTab(0)"><b>待提交</b></view><view v-show="tab == 0" class="num ac">{{count > 99 ? '99+' : count}}</view></view>
			<view class="fl menu ac"><view :class="{on:tab == 1}" @click="setTab(1)"><b>待处理</b></view><view v-show="tab == 1" class="num ac">{{count > 99 ? '99+' : count}}</view></view>
			<view class="fl menu ac"><view :class="{on:tab == 2}" @click="setTab(2)"><b>待验证</b></view><view v-show="tab == 2" class="num ac">{{count > 99 ? '99+' : count}}</view></view>
			<view class="fl menu ac" @click="show_search = true"><view>筛选<image class="select" src="/static/img/select.png"></image></view></view>
			
			<view class="clearfix"></view>
		</view>
		
		<view class="work-item">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="name"><b>{{item.WT_CATEGORY || '--'}}</b>
					<view class="fr" @click="jumpSubmit(item)"><button v-show="item.FLOWSTATENAME == '待提交'" class="default-btn push">编辑</button></view>
					<view class="fr" @click="removeItem(item,index)"><button v-show="item.FLOWSTATENAME == '待提交'" class="cancel-btn push" style="margin-right: 10px;">删除</button></view>
				</view>
				<view @click="jumpUrl(item)"><view class="f-opactiy">检查人：</view>{{item.JCPERSONNAME}}</view>
				<view @click="jumpUrl(item)"><view class="f-opactiy">责任部门：</view>{{item.ZRORGNAME}}</view>
				<image v-show="item.FLOW_STATE==1" src="/static/img/untreated.png" class="item-status"></image>
			</view>
		</view>
		
		<QuestionSearch v-show="show_search" :type="tab" @closeFull="closeFull"></QuestionSearch>
	</view>
</template>

<script>
import QuestionSearch from '../../components/question/questionSearch'
export default{
	components:{QuestionSearch},
	data() {
		return {
			tab : 1,
			// start : '',
			// end : '',
			list : [],
			search : {
				"flowState": "0",  // 流转状态 0 已保存  ,1 待处理,2 待验证,3销号 4未销号
				"jcEndTime": "", //检查结束时间
				"jcOrg": uni.getStorageSync('departid'),  //检查部门名称
				"jcPerson": this.getUserId(), //检查人名称 
				"jcStartTime": "",  //检查开始时间
				"zrOrg": "", //责任部门名称
				"zrPerson": ""//责任人名称
			},
			count : 0,
			show_search : false,
			flog : true
		}
	},
	// onReachBottom() {
	// 	if(!this.flog) return uni.showToast({title:'已无最新数据',icon:'none'});
	// 	this.initList();
	// },
	created() {
		this.initList();
	},
	methods: {
		back() {
			uni.navigateTo({
			    url: '/pages/index/index'
			});
		},
		setTab(i) {
			if(this.tab == i) return;
			this.tab = i;
			if(this.tab == 2) this.getCount();
			if(this.tab != 4) {
				this.search = {
					"flowState": "0",  // 流转状态 0 已保存  ,1 待处理,2 待验证,3销号 4未销号
					"jcEndTime": "", //检查结束时间
					"jcOrg": uni.getStorageSync('departid'),  //检查部门名称
					"jcPerson": this.getUserId(), //检查人名称 
					"jcStartTime": "",  //检查开始时间
					"zrOrg": "", //责任部门名称
					"zrPerson": ""//责任人名称
				};
				this.list = [];
			}
			this.initList();
		},
		addQuestion() {
			uni.navigateTo({
			    url: '/pages/question/addQuestion'
			});
		},
		jumpSubmit(obj) {
			uni.setStorageSync('question', JSON.stringify(obj));
			uni.navigateTo({
			    url: '/pages/question/pushQuestion'
			});
		},
		jumpUrl(obj) {
			if(obj.FLOWSTATENAME == '待提交') return;
			uni.setStorageSync('question', JSON.stringify(obj));
			uni.navigateTo({
			    url: '/pages/question/detail'
			});
		},
		closeFull(obj) {
			if(obj) {
				this.search = obj;
				this.search.jcStartTime = this.search.jcStartTime.replace(/\//g,'-');
				this.search.jcEndTime = this.search.jcEndTime.replace(/\//g,'-');
				this.initList();
			}
			this.show_search = false;
		},
		initList() {
			this.search.flowState = this.tab;
			this.fetch('POST',this.baseUrl()+'/cascoAppWentiController/listWenti',this.search,true).then((res)=>{
				if(res.returnCode == 1) {
					this.list = res.data.content;
					this.count = res.data.totalElements;
				}
			})
		},
		removeItem(obj,i) {
			this.fetch('POST',this.baseUrl()+'/cascoAppWentiController/delWenti',{id:obj.ID},true).then((res)=>{
				uni.showToast({title:res.message,icon:'none'});
				if(res.returnCode == 1) {
					this.list.splice(i,1);
					this.count = this.count-1;
				}
			})
		},
		getCount() {
			// this.fetch('POST',this.baseUrl()+'/cascoAppWentiController/getDaiChuLiCount',{flowState:'1'}).then((res)=>{
			// 	if(res.returnCode == 1) this.count = res.data;
			// })
		}
	}
}
</script>

<style scoped>
	.my-work{
		background:#fff;margin-bottom: 16px;box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.05);
	}
	.my-work>.menu{
		width: 19%;color: #3E3A39;line-height: 54px;position: relative;
	}
	.my-work>.menu:nth-child(5){
		border-left: 1px solid #d7d7d7;width: 24%;
	}
	.my-work>.menu view{
		display: inline-block;
	}
	.my-work>.menu>.on{
		color: #307BE0;border-bottom: 2px solid #307BE0;
	}
	.my-work>.menu>.num{
		position: absolute;top:10px;right:3%;background:#FA5151;width: 15px;height: 15px;font-size: 10px;border-radius: 50%;color: #fff;line-height: 14px;
	}
	.select{
		width: 15px;height: 15px;margin-left: 5px;vertical-align: middle;
	}
	.work-item{
		width: 91.5%;margin: 0 auto;
	}
	.work-item>.item{
		background: #FFFFFF;box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.05), 2px 2px 4px rgba(0, 0, 0, 0.05);border-radius: 6px;padding: 0 16px 16px 16px;font-size: 14px;margin-bottom: 16px;color: #3E3A39;position: relative;
	}
	.work-item>.item>.name{
		margin-bottom: 10px;line-height: 48px;border-bottom: 1px solid #F1F1F1;
	}
	.work-item>.item>view:nth-child(2){
		margin-bottom: 6px;
	}
	.work-item>.item>.item-status{
		position: absolute;width: 60px;height: 60px;right: 0;bottom: 6px;
	}
	.push{
		width: 60px;line-height: 26px;border-radius: 6px;
	}
	.work-item>.item>.name>.fr{
		display: inline-flex;align-items: center;height: 48px;
	}
	.f-opactiy{
		display: inline-block;
	}
</style>
